Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add x86_64-apple-darwin target #480

Closed
wants to merge 1 commit into from

Conversation

ChrisRx
Copy link

@ChrisRx ChrisRx commented Nov 4, 2020

This adds support for the x86_64-apple-darwin target using osxcross. This would fix #223 (at least partially depending upon desire for other darwin targets like i386) and maybe addresses #436 because of the changes made to needs_docker() in src/main.rs.

I tried to reuse/imitate as many things as I could from the other targets to try and make the first pass at this consistent with them, but let me know if something is missing or needs to be improved.

@ChrisRx ChrisRx requested review from Dylan-DPC-zz and a team as code owners November 4, 2020 21:15
@ChrisRx ChrisRx force-pushed the add-darwin-target branch 2 times, most recently from 0d7e2da to c8c6193 Compare November 5, 2020 13:07
This adds support for the x86_64-apple-darwin target using [osxcross](https://github.com/tpoechtrager/osxcross).
@brooksmtownsend
Copy link

Any updates on this? @Dylan-DPC Would love to have the apple-darwin target included with cross!

@Dylan-DPC-zz
Copy link

@brooksmtownsend sorry have been busy so didn't get a chance to look at this. Will have a look when I have time. I'm assuming we will need to add a CI target as well?

@Absolucy
Copy link

Would aarch64-apple-darwin be possible with this, too?

@ChrisRx
Copy link
Author

ChrisRx commented Mar 4, 2021

@brooksmtownsend sorry have been busy so didn't get a chance to look at this. Will have a look when I have time. I'm assuming we will need to add a CI target as well?

Yeah, I think it would need a CI target but I wasn't quite sure how to add one that would test compiling x86_64-apple-darwin on linux. Does someone have an idea on what would need to be changed? I presume it is adding something to this file: https://github.com/rust-embedded/cross/blob/master/azure-pipelines.yml

@UebelAndre
Copy link
Contributor

Hey, just pinging this issue, it'd be great to have the docker files in even if building them requires users provide their own SDK bundles per the README. It would also be wonderful if there were one added for aarch64 🙏. I don't think it'd be too much more work but can also see that as a separate PR

@schlumpfit
Copy link

schlumpfit commented Jun 17, 2021

Hello I am fairly new to rust but I run into an issue when cross-compiling a cli-tool which makes use of hyper from Ubuntu20.04 for x86_64-apple-darwin

error: linking with `cc` failed: exit code: 1
   |
  = note: "cc" "-m64" "-arch" "x86_64" "-L" ... "-liconv" "-lSystem" "-lresolv" "-lc" "-lm"
  = note: cc: error: x86_64: No such file or directory
               cc: error: unrecognized command line option '-arch'
error: aborting due to previous error
error: could not compile `hyper`.

Not sure if I understood everything correctly, but it seems like hyper is not compiled as staticlib and therefore needs to compile c-dependencies where it falls back to CC and CXX of the host.
So overwriting these in the ENV to clang (which I guess will be wrapped by osxcross) helped me to compile/link hyper:

ENV CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=x86_64-apple-darwin14-clang \
    CARGO_TARGET_X86_64_APPLE_DARWIN_AR=x86_64-apple-darwin14-ar \
    CC_x86_64_apple_darwin=o64-clang \
    CXX_x86_64_apple_darwin=o64-clang++ \
    
    CC=o64-clang \
    CXX=o64-clang++

Not sure though if this acceptable in all circumstances.

Credits: https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html

@reitermarkus
Copy link
Member

@ChrisRx, could you rebase this and try adding a target?

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Jun 16, 2022

I don't think we can legally provide this as a pre-built image, and the an example of a major project that used this (and then removed it likely for legal reasons) is moby (Docker) itself, which did in early 2017 (see b96093f/Dockerfile where it's gone and f8dacaf/Dockerfile where it exists). However, we can provide a Dockerfile and tell users how to build it, as long as we don't integrate it in CI.

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Jun 23, 2022

Superseded in favor of #841. This provides a Dockerfile that we can ship legally, where we do not provide the SDK, so we do not run into legal issues distributing the macOS SDK in pre-built images. This Dockerfiles are live on cross-rs/cross-toolchains, and you can follow the instructions on the README to build the images.

For example, for the full workflow for building an x86_64 target is as follows:

$ git clone https://github.com/cross-rs/cross
$ cd cross
$ git submodule update --init --remote
# now, you can provide either `MACOS_SDK_URL` or `MACOS_SDK_FILE`
# `MACOS_SDK_DIR` is optional if `MACOS_SDK_FILE` is provided.
$ MACOS_SDK_URL=...
$ MACOS_SDK_FILE=...
$ cargo build-docker-image x86_64-apple-darwin-cross \
  --build-arg 'MACOS_SDK_URL=$URL'
$ cargo build-docker-image x86_64-apple-darwin-cross \
  --build-arg 'MACOS_SDK_DIR=$DIR' \
  --build-arg 'MACOS_SDK_FILE=$FILE'

Your Cross.toml file would then look like:

[target.x86_64-apple-darwin]
image = "ghcr.io/cross-rs/x86_64-apple-darwin-cross:local"

[target.i686-apple-darwin]
image = "ghcr.io/cross-rs/i686-apple-darwin-cross:local"

And now you can build as normal. This only needs Docker or Podman installed, so it won't require an additional dependency.

$  cross build --target x86_64-apple-darwin

I hope this is satisfactory for all involved?

@Alexhuszagh Alexhuszagh mentioned this pull request Jun 24, 2022
@Alexhuszagh Alexhuszagh mentioned this pull request Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Darwin targets
8 participants